package mcdevitt.id.projects;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Game {
	private Scanner input = new Scanner(System.in);
	private int userOptionSelection;
	private boolean playing = true;
	private int wins=0;
	private int losses=0;
//makes sure the user input is in a integer
	//prints error if input not int
	public int getInt(Scanner input) {
		while (true) {
			try {
				userOptionSelection = input.nextInt();
				break;
			} catch (InputMismatchException e) {
				System.out.print("ERROR. Please enter an integer:");
				input.nextLine();
			}
		}
		return userOptionSelection;
	}
//prints error if input is not between 1-2
	public int getValidOptionSelection(Scanner input) {
		int i;
		while (true) {
			i = getInt(input);
			if (i >= 0 && i <= 2) {

				break;
			} else {
				System.out
						.print("ERROR. Please enter an integer between 1 and 2:");
				input.nextLine();
			}
		}
		return i;
	}
	//prints player's wins and losses
	public void printRecord(){
		System.out.println("Wins: "+wins+"  "+"Losses: "+losses);
	}
		
	
//starts the game
	public void start() {
		
		while (playing) {
			BlackJack game = new BlackJack();
			printRecord();
			int outcome=game.play();
			if(outcome==1){
				wins++;
			}
			else if(outcome==2){
				losses++;
			}
			System.out.println("Would you like to play again?");
			System.out.print("1.Yes  2.No:");
			int userOptionSelection = getValidOptionSelection(input);
			switch (userOptionSelection) {
			// yes
			case 1:
				System.out.println("________________________");
				break;
			// no
			case 2:
				playing = false;
				break;
			}
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("\u2660 " + " \u2663 " + " \u2665 " + " \u2666 "
				+ " \u2660 " + " \u2663 " + " \u2665 " + " \u2666 ");
		System.out.println("\u2663" + "                    " + "\u2663");
		System.out.println("\u2665" + "     Black Jack!    " + "\u2665");
		System.out.println("\u2665" + "                    " + "\u2665");
		System.out.println("\u2660 " + " \u2663 " + " \u2665 " + " \u2666 "
				+ " \u2660 " + " \u2663 " + " \u2665 " + " \u2666 ");
		Game blackJack = new Game();
		blackJack.start();

	}

}
